<?php
/**
 * Class IndexController
 */
class IndexController extends AppControllerAction
{
    function init()
    {
        parent::init();  
    } 
    
    function indexAction()
    {
        $property = new Property();
        
        $this->view->feature = $property->getListProperty(' status = '.FEATURE_PROPERTY,'created desc',1,2)->toArray();
        
        $welcome = new Welcome();
        $this->view->welcome = $welcome->getById(1)->toArray();
  	      
    } 
       
    function loginformAction()
    {
        $userModel= new Users();
        if($userModel->isAuthenticated())
        {
            $this->_helper->viewRenderer->setNoRender();            
        }
    }
    
    function quicksearchformAction()
    {
        $city = new City();
        $this->view->listCity = $city->getListCity()->toArray();           
    }
    
    function favoriteformAction()
    {
        $property = new Property();
        $this->view->favorites = $property->getListProperty(' status = '.FEATURE_PROPERTY, 'created desc', 1, 2)->toArray();
    }
    
    function hotpropertyformAction()
    {
        $property = new Property();
        $this->view->hots = $property->getListProperty(' status = '.HOT_PROPERTY, 'created desc', 1, 3)->toArray();   
    }
    
    function serviceformAction()
    {
        $service = new ServiceCategory();
        $this->view->service = $service->getListServiceCategory('', 'id', 1, 4)->toArray();    
    }
    function relaxformAction()
    {
        $relax = new RelaxCategory();
        $this->view->relax = $relax->getListRelaxCategory('', 'id', 1, 4)->toArray();
    }
    
    function propertyformAction()
    {
        $city = new City();
        $this->view->city = $city->getListCity('', 'id', 1, 4)->toArray();        
    }
    
    function loginAction()
    {
        $username = trim($this->_request->getParam('username'));
        $password = trim($this->_request->getParam('password')); 
        
        if($username != '' && $password != '') 
        {      
            $userModel = new Users();        
            $userModel->login($this->_request->getParam('username'),$this->_request->getParam('password'));
        }
        
        $this->_redirect();
    }
    
    function businessAction()
    {
        if($this->_request->isPost())       
            $this->_request->setParamSources(array('_POST'));               
        else
            $this->_request->setParamSources(array('_GET'));                     
        $params = $this->_request->getParams();  
        
        $category = isset($params["category"])?$params["category"]:'';   
            $where ='';
        if($category!='')
            $where .= " category = ".$category;
                        
        $service = new Service();
        
        $this->view->services = $service->getListService($where, 'created desc')->toArray();
    }
    
    function businessdetailsAction()
    {
        $id = $this->_request->getParam('id',0);
        
        $service = new Service();
        $this->view->service = $service->getById($id)->toArray();      
    }
    
    function officeAction()
    {
        $property = new Property();        
        $this->view->listproperty = $property->getListProperty()->toArray();     
    }
    
    function officedetailsAction()
    {
        $id = $this->_request->getParam('id',0);
        
        $property = new Property();
        $this->view->property = $property->getById($id)->toArray();      
    }
    
    function searchAction()
    {
            $city = new City();
            $this->view->listCity = $city->getListCity()->toArray();                     
    }
    
    function searchresultAction()
    {
        if($this->_request->isPost())       
            $this->_request->setParamSources(array('_POST'));               
        else
            $this->_request->setParamSources(array('_GET'));                     
        $params = $this->_request->getParams();  
        
        
        $name = isset($params["name"])?$params["name"]:'';   
        $city = isset($params["city"])?$params["city"]:'';   
        $street = isset($params["street"])?$params["street"]:'';   
        $state = isset($params["state"])?$params["state"]:'';   
        $area = isset($params["area"])?$params["area"]:'';   
        $low = isset($params["low"])?$params["low"]:'';   
        $high = isset($params["high"])?$params["high"]:'';   
        $type = isset($params["type"])?$params["type"]:'';   
                
        $this->view->name = $name;
        $this->view->city = $city;
        $this->view->street = $street;
        $this->view->state = $state;
        $this->view->area = $area;
        $this->view->low = $low;
        $this->view->high = $high;
        $this->view->type = $type;
                    
        $where = '';  
        
        if($name!='')
            $where .= " name like '%".addslashes($name)."%' ";
        if($city!='')
            $where .= ($where==''?'':' and ')." city = ".$city." ";
        if($street!='')
            $where .= ($where==''?'':' and ')." street like '%".addslashes($street)."%' ";
        if($state!='')
            $where .= ($where==''?'':' and ')." state like '%".addslashes($state)."%' ";
        if($area!='')
            $area .= ($where==''?'':' and ')." area = ".addslashes($area)." ";
        if($low!='')
            $where .= ($where==''?'':' and ')." price <= '".addslashes($low)."' ";
        if($high!='')
            $where .= ($where==''?'':' and ')." price >= '".addslashes($high)."' ";
        if($type!='')
            $where .= ($where==''?'':' and ')." type = ".$type." ";
                  
       $property = new Property();
          
       $this->view->listproperty = $property->getListProperty($where)->toArray(); 
       
    }
    
    function relaxAction()
    {
        if($this->_request->isPost())       
            $this->_request->setParamSources(array('_POST'));               
        else
            $this->_request->setParamSources(array('_GET'));                     
        $params = $this->_request->getParams();  
        
        $category = isset($params["category"])?$params["category"]:'';   
            $where ='';
        if($category!='')
            $where .= " category = ".$category;
                        
        $relax = new Relax();        
        $this->view->relaxs = $relax->getListRelax($where, 'created desc')->toArray();
    }
    
    function relaxdetailsAction()
    {
         $id = $this->_request->getParam('id',0);
        
        $relax = new Relax();
        $this->view->relax = $relax->getById($id)->toArray();      
    }
    
    function contactAction()
    {
        $city = new City();         
        $this->view->city = $city->getListCity()->toArray();
        
        if($this->_request->isPost())  
        {
            $contact = new Contact();
            
            $contact->setName($this->_request->getParam('name','default'));
            $contact->setEmail($this->_request->getParam('email','default'));
            $contact->setCity($this->_request->getParam('city',1));
            $contact->setStreet($this->_request->getParam('street','default'));
            $contact->setState($this->_request->getParam('state','default'));
            $contact->setContent($this->_request->getParam('content','default'));
            
            $contact->save();
        
        }
        
    }
}
?>